/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tracksuite.util;

import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import tracksuite.integration.GenericDAO;

/**
 *
 * @author mfloriano
 */
public final class ContextListener<DAO extends GenericDAO> implements ServletContextListener {

    private DAO dao;
    private ServletContext context;
    
    @PersistenceUnit
    private EntityManagerFactory emf;

    public void contextInitialized(ServletContextEvent event) {
        context = event.getServletContext();
        dao.setEntityManagerFactory(emf);
        context.setAttribute(dao.getClass().getName(), dao);
    }

    public void contextDestroyed(ServletContextEvent event) {}
    
}
